var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var $2kc = require("kc");
var $2KDefine = require("KDefine");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_pvzRecordVideoBt = /* */function (_cc$Component90) {
  babel_inherits(d, _cc$Component90);
  var _super124 = babel_createSuper(d);
  function d() {
    var _this297;
    babel_classCallCheck(this, d);
    _this297 = _super124.apply(this, arguments);
    _this297.txt = null;
    _this297.pic = null;
    _this297.rState = "idle";
    _this297.recordTime = 0;
    _this297.main = null;
    return _this297;
  }
  babel_createClass(d, [{
    key: "onLoad",
    value: function onLoad() {
      var _this298 = this;
      this.node.on(cc.Node.EventType.TOUCH_END, function () {
        if ("tt" !== $2pvzChannel.pvzChannel.instance().channel || 1 !== $2pvzChannel.pvzChannel.instance().getCtrl("p1")) {
          if ("idle" === _this298.rState) {
            $2pvzChannel.pvzChannel.instance().recorderStart();
          } else if ("recording" === _this298.rState) {
            $2pvzChannel.pvzChannel.instance().recorderStop();
            $2pvzChannel.pvzChannel.instance().getRecordTime() > 15e3 && _this298.main.showShareVideoWin();
          } else if ("recordEnd" === _this298.rState) {
            _this298.main.showShareVideoWin(), _this298.rState = "idle", _this298.updateUI();
          }
        } else {
          $2pvzChannel.pvzChannel.instance().shareVideo();
        }
      }, this);
      $2kc.default.regMsgReciever($2KDefine.Msg.recorderStart, function () {
        _this298.recordTime = 0;
        _this298.rState = "recording";
        _this298.unschedule(_this298.updateTime);
        _this298.schedule(_this298.updateTime, 1, cc.macro.REPEAT_FOREVER);
        _this298.updateUI();
        return true;
      });
      $2kc.default.regMsgReciever($2KDefine.Msg.recorderStop, function () {
        _this298.rState = "recordEnd";
        _this298.unschedule(_this298.updateTime);
        _this298.updateUI();
        return true;
      });
      $2kc.default.regMsgReciever($2KDefine.Msg.recorderFail, function () {
        _this298.rState = "idle";
        _this298.recordTime = 0;
        _this298.unschedule(_this298.updateTime);
        _this298.updateUI();
        return true;
      });
      $2kc.default.regMsgReciever($2KDefine.Msg.recorderDone, function () {
        _this298.rState = "idle";
        _this298.recordTime = 0;
        _this298.unschedule(_this298.updateTime);
        _this298.updateUI();
        return true;
      });
    }
  }, {
    key: "updateTime",
    value: function updateTime() {
      if ("recording" === this.rState) {
        this.recordTime++;
        this.recordTime > 300 && $2pvzChannel.pvzChannel.instance().recorderStop();
        this.updateUI();
      }
    }
  }, {
    key: "show",
    value: function show(e) {
      this.main = e;
      this.node.active = true;
      $2pvzChannel.pvzChannel.instance().recorderStart();
    }
  }, {
    key: "updateUI",
    value: function updateUI() {
      if (this.txt) {
        if ("recording" === this.rState) {
          this.txt.node.color !== cc.Color.RED && (this.txt.node.color = cc.Color.RED);
          this.txt.string = "录制中" + $2kc.default.showPassTime(this.recordTime);
          this.pic.spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShareUI/pause", cc.SpriteFrame);
        } else if ("recordEnd" === this.rState) {
          this.txt.node.color !== cc.Color.BLACK && (this.txt.node.color = cc.Color.BLACK);
          this.txt.string = "点击分享";
          this.pic.spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShareUI/play", cc.SpriteFrame);
        } else {
          this.pic.spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShareUI/play", cc.SpriteFrame);
          this.txt.string = "";
        }
      }
    }
  }]);
  return d;
}(cc.Component);
cc__decorate([ccp_property(cc.Label)], def_pvzRecordVideoBt.prototype, "txt", undefined);
cc__decorate([ccp_property(cc.Sprite)], def_pvzRecordVideoBt.prototype, "pic", undefined);
def_pvzRecordVideoBt = cc__decorate([ccp_ccclass], def_pvzRecordVideoBt);
exports.default = def_pvzRecordVideoBt;